package com.mrx.xfriendship.converter;

import com.mrx.xfriendship.model.dto.UserManagerDTO;
import com.mrx.xfriendship.model.po.UserPO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;

import javax.annotation.Resource;

/**
 * @author Mr.X
 * @since 2023-01-21 18:31
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public abstract class UserManagerDTOConverter implements IConverter<UserPO, UserManagerDTO> {

    @Resource
    protected OtherConverter otherConverter;

    @Override
    @Mapping(target = "name", expression = "java( po.getName() )")
    @Mapping(target = "avatar", expression = "java( otherConverter.toPreviewAvatar(po.getUserDetail().getAvatar()) )")
    @Mapping(target = "role", expression = "java( po.getUserDetail().getRole().getRole() )")
    @Mapping(target = "gender", expression = "java( otherConverter.gender2String(po.getUserDetail().getGender()) )")
    @Mapping(target = "contact", expression = "java( po.getUserDetail().getContact() )")
    @Mapping(target = "birthDay", expression = "java( po.getUserDetail().getBirthDay() )")
    public abstract UserManagerDTO toDTO(UserPO po);

}
